package com.kyh.entity.base;

public class OrderBy {
	private Integer size; // 每页条数
	private Integer page; // 起始数
	private String orderby; // 排序字段，值可以是驼峰，也可以是原数据库字段
	private String sorttype; // 排序方式
	
	public boolean isCount;
	
	public Integer getSize() {
		return size;
	}
	public void setSize(Integer limit) {
		this.size = limit;
	}
	public Integer getPage() {
		return page;
	}
	public void setPage(Integer start) {
		this.page = start;
	}
	public String getOrderby() {
		return orderby;
	}
	
	/**
	 * 设置排序方式
	 * @param orderby格式：A.merchant_id asc,B.xxx desc
	 */
	public void setOrderby(String orderby) {
		this.orderby = orderby;
	}
	public String getSorttype() {
		return sorttype;
	}
	public void setSorttype(String sorttype) {
		this.sorttype = sorttype == null ? "desc" : sorttype;
	}
	public boolean getIsCount() {
		return isCount;
	}
	public void setIsCount(boolean isCount) {
		this.isCount = isCount;
	}
	
	@Override
	public String toString() {
		StringBuffer sb = new StringBuffer();
		if (orderby != null && orderby.length() > 0) {
			sb.append("order by " + orderby + " ");
			if (sorttype != null && sorttype.length() > 0) {
				sb.append(sorttype + " ");
			} else {
				sb.append("asc ");
			}
		}
		
		if (size != null && page != null) {
			sb.append("limit " + page + "," + size + "");
		}
		return sb.toString();
	}
}
